package cn.stylefeng.guns.modular.board.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import cn.stylefeng.guns.modular.system.model.InfoBoard;
import cn.stylefeng.guns.modular.board.service.IInfoBoardService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2019-04-26 18:00:14
 */
@Controller
@RequestMapping("/infoBoard")
public class InfoBoardController extends BaseController {

    private String PREFIX = "/board/infoBoard/";

    @Autowired
    private IInfoBoardService infoBoardService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "infoBoard.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/infoBoard_add")
    public String infoBoardAdd() {
        return PREFIX + "infoBoard_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/infoBoard_update/{infoBoardId}")
    public String infoBoardUpdate(@PathVariable Integer infoBoardId, Model model) {
        InfoBoard infoBoard = infoBoardService.selectById(infoBoardId);
        model.addAttribute("item",infoBoard);
        LogObjectHolder.me().set(infoBoard);
        return PREFIX + "infoBoard_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return infoBoardService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(InfoBoard infoBoard) {
        infoBoardService.insert(infoBoard);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer infoBoardId) {
        infoBoardService.deleteById(infoBoardId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(InfoBoard infoBoard) {
        infoBoardService.updateById(infoBoard);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{infoBoardId}")
    @ResponseBody
    public Object detail(@PathVariable("infoBoardId") Integer infoBoardId) {
        return infoBoardService.selectById(infoBoardId);
    }
}
